package mp

import (
	"context"

	"ruikc.com/server/api/internal/db"
	"ruikc.com/server/api/internal/svc"
	"ruikc.com/server/api/internal/types"
	"ruikc.com/server/models"
	xb "xorm.io/builder"

	"github.com/zeromicro/go-zero/core/logx"
)

type CategorySortLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCategorySortLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CategorySortLogic {
	return &CategorySortLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CategorySortLogic) CategorySort(req *types.SortReq) (resp string, err error) {
	for _, v := range req.Data {
		data := models.Category{
			SortNum: v.SortNum,
		}
		db.UpdateData(&data, xb.Eq{"id": v.Id})
	}
	return "操作成功", nil
}
